//
// Created by guanyicheng on 2021/9/15.
//
#include "../../common.h"

// The API isBadVersion is defined for you.
bool isBadVersion(int version);

class Solution {
public:
    int firstBadVersion(int n) {
        long left = 0, right = (long)n + 1;
        while (left < right) {
            int mid = left + ((right - left) >> 1);
            if (isBadVersion(mid)) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        if (isBadVersion(right)) {
            return right;
        }
        return -1;
    }
};

bool isBadVersion(int version) {
    return version >= 1;
}

int main() {

    cout << Solution().firstBadVersion(1) << endl;
}